package com.navigationtest;

import com.pbase.tools.Logger;
import com.pbase.ui.page.BaseFragment;

import androidx.activity.OnBackPressedCallback;
import androidx.navigation.Navigation;

/**
 * User: psn
 * Date: 2021/12/30
 */
public abstract class NavigationViewFragment extends BaseFragment {
    @Override
    protected void onCreateViewAfter() {
        requireActivity().getOnBackPressedDispatcher()
                .addCallback(new OnBackPressedCallback(true) {
            @Override
            public void handleOnBackPressed() {
                //拦截返回事件 但是拦截的是该activity整体的返回键
//            moveTaskToBack(true);
//                Fragment fragment = AppManager.getInstance().currentFragment();
//                if (fragment instanceof  Test5Fragment){
//                    Logger.e(getClass(),"Test5Fragment NavigationViewFragment handleOnBackPressed");
//                }else {
//                    left();
//                }

            }
        });
    }
    public void left() {
        Logger.e(getClass(),"left NavigationViewFragment handleOnBackPressed");
        Navigation.findNavController( NavigationViewFragment.this.getView()).navigateUp();
    }
}
